import { Router } from 'express';
import { VoteController } from '../../admin/controllers/voteController';
import { authenticate, authorize } from '../../middleware/auth';
import { ALL_PERMISSIONS } from '../../constants/permissions';
const router = Router();
const voteController = new VoteController();

/**
 * @swagger
 * /api/admin/votes/statistics:
 *   get:
 *     summary: 获取投票统计
 *     tags: [Admin - Votes]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: startDate
 *         schema:
 *           type: string
 *           format: date
 *         description: 开始日期
 *       - in: query
 *         name: endDate
 *         schema:
 *           type: string
 *           format: date
 *         description: 结束日期
 *       - in: query
 *         name: artistId
 *         schema:
 *           type: integer
 *         description: 艺人ID
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取投票统计成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     overview:
 *                       type: object
 *                       properties:
 *                         totalVotes:
 *                           type: integer
 *                         totalVoters:
 *                           type: integer
 *                         totalArtists:
 *                           type: integer
 *                     topArtists:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           artistId:
 *                             type: integer
 *                           artist:
 *                             $ref: '#/components/schemas/Artist'
 *                           totalVotes:
 *                             type: integer
 *                     dailyVotes:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           date:
 *                             type: string
 *                           votes:
 *                             type: integer
 *                     topVoters:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           userId:
 *                             type: integer
 *                           user:
 *                             $ref: '#/components/schemas/User'
 *                           totalVotes:
 *                             type: integer
 *                     artistStats:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           artistId:
 *                             type: integer
 *                           artist:
 *                             $ref: '#/components/schemas/Artist'
 *                           totalVotes:
 *                             type: integer
 *                           voterCount:
 *                             type: integer
 */
router.get('/statistics', authenticate, authorize([ALL_PERMISSIONS.VOTE_READ]), voteController.getVoteStatistics);

/**
 * @swagger
 * /api/admin/votes/reset:
 *   post:
 *     summary: 重置投票数据
 *     tags: [Admin - Votes]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               artistId:
 *                 type: integer
 *                 description: 艺人ID（可选，不传则重置所有投票）
 *     responses:
 *       200:
 *         description: 重置成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 已重置所有投票数据
 */
router.post('/reset', authenticate, authorize([ALL_PERMISSIONS.VOTE_DELETE]), voteController.resetVotes);

/**
 * @swagger
 * /api/admin/votes:
 *   get:
 *     summary: 获取投票详情列表
 *     tags: [Admin - Votes]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 每页数量
 *       - in: query
 *         name: artistId
 *         schema:
 *           type: integer
 *         description: 艺人ID
 *       - in: query
 *         name: userId
 *         schema:
 *           type: integer
 *         description: 用户ID
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取投票列表成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     list:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           id:
 *                             type: integer
 *                           userId:
 *                             type: integer
 *                           artistId:
 *                             type: integer
 *                           voteCount:
 *                             type: integer
 *                           createdAt:
 *                             type: string
 *                             format: date-time
 *                           user:
 *                             $ref: '#/components/schemas/User'
 *                           artist:
 *                             $ref: '#/components/schemas/Artist'
 *                     pagination:
 *                       $ref: '#/components/schemas/Pagination'
 */
router.get('/', authenticate, authorize([ALL_PERMISSIONS.VOTE_READ]), voteController.getVotes);

/**
 * @swagger
 * /api/admin/votes/{id}:
 *   delete:
 *     summary: 删除投票记录
 *     tags: [Admin - Votes]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 投票记录ID
 *     responses:
 *       200:
 *         description: 删除成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 删除投票记录成功
 */
router.delete('/:id', authenticate, authorize([ALL_PERMISSIONS.VOTE_DELETE]), voteController.deleteVote);

export default router; 